﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using SmartCountersDeployer;


namespace SmartCounters
{
	public partial class ApplicationDeployer : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
		}

		[WebMethod]
		public static string DeployApplication(string i_ServerName,string i_DBName, string i_AppUserName, string i_AppUserPassword, string i_SQLAdminUserName, string i_SQLAdminPassword)
		{
			string result = "";
			DBDeployer dbDeployer = new DBDeployer(i_SQLAdminUserName, i_SQLAdminPassword, i_ServerName, i_DBName, i_AppUserName, i_AppUserPassword);

			try
			{
				dbDeployer.DeployDB();
                dbDeployer.InsertDummyInformation();
				result = string.Format(@"SmartCounters Application database was deployed successfully with the following parameters:

							Server Name: {0}
							SQL Admin Username: {1}
							SQL Admin Password: {2}
							Application Database Name: {3}
							Application Username: {4}
							Application Password: {5}",
							i_ServerName,
							i_SQLAdminUserName,
							i_SQLAdminPassword,
							i_DBName,
							i_AppUserName,
							i_AppUserPassword);

			}
			catch (Exception e)
			{
				result = "Error: " + e.Message + Environment.NewLine + e.Data["Phase"];
			}

			return result;
		}
	}
}